<?php
class MembershipAction extends PublicAction {
	//会员首页
	public function index(){
		$uid = session('uid');
		$this->checkuid($uid,U('Membership/index'));		
		$this->msg = I('msg',0);
		
		$member = M('membership')->where(array('uid'=>$uid))->find();		 
		$this->member = $member;
		$this->uid = $uid;
		$this->display();
	}
	
	public function login(){
		if($_POST){
			$tel = I('tel');
			$pwd = I('pwd');
			$member = M('membership')->where(array('tel'=>$tel,'pwd'=>md5($pwd)))->find();
			//var_dump($member);die;
			if($member['uid']){
				session('uid',$member['uid']);
				$data['uid'] = $member['uid'];
				$data['login_date'] = date('Y-m-d H:i:s',time());
				M('member_login')->add($data);
				$back =  $_SERVER['SERVER_NAME'].session('back');
				//echo $back;die;
				$refer = session('refer');
				header("location:" . $refer."?msg=登录成功");
				//echo $refer;die;
				//$this->redirect('Membership/index',array('msg'=>'登录成功'));
				//$this->back=$back
			}else{
				$this->msg = '用户名或密码错误！';
				$this->display();
			}
		}else{
			$this->msg = I('msg',0);
			$this->display();
		}
		
	}
	
	//退出登录
	public function logout(){
		session('uid',null);
		$this->redirect('Membership/login',array('msg'=>'退出账号成功！'));
	}
	
	/**
	 * 用户信息详细资料及修改
	 */
	public function memberdetail(){
		$uid = session('uid');
		$this->checkuid($uid,U('Membership/memberdetail'));
		if(IS_POST){
			$changeheadimg= I('changeheadimg','');
			if($changeheadimg==1){
				$this->removePic();
			}
			$data['name'] = I('name');
			$data['headimg'] = I('headimg','');
			$data['provcode'] = I('provcode');
			$data['citycode'] = I('citycode');
			$data['area_id'] = I('area_id');
			$result = M('membership')->where(array('uid'=>$uid))->save($data);		
		}
		$membership = M('membership')->where(array('uid'=>$uid))->find();
		$this->membership = $membership;
		$this->msg = $msg?$msg:0;
		$this->display();
	}
	/**
	 * 删除会员头像
	 */
	public function removePic(){
		$uid = session('uid');
		$member = M('membership')->where(array('uid'=>$uid))->field('headimg')->find();
		@unlink("./Public/images/memberhead/".$member['headimg']);
		@unlink("./Public/images/memberhead/thumb/m_".$member['headimg']);
		@unlink("./Public/images/memberhead/thumb/s_".$member['headimg']);
		$result = M('membership')->where(array('uid'=>$uid))->setField('headimg','');
	}
	/*
	 * 修改密码
	 */
	public function changepwd(){
		$uid = session('uid');
		$this->checkuid($uid,U('Membership/changepwd'));
		if($_POST){
			$member = M('membership')->where(array('uid'=>$uid))->field('pwd')->find();
			$oldpwd = I('oldpwd');
			if(md5($oldpwd)!=$member['pwd']){
				$msg = '旧密码输入错误，请重新输入！';
			}else{
				$pwd = I('pwd');
				$result = M('membership')->where(array('uid'=>$uid))->setfield('pwd',md5($pwd));
				if($result){
					session('uid',null);
					$this->redirect('Membership/login',array('msg'=>'修改密码成功，请重新登录！'));
				}else{
					$msg = '修改密码失败，请联系管理人员';
				}
			}
			
			
		}
		$this->msg = $msg?$msg:0;
		$this->display();
	}
	
	
    /*
     * 会员注册界面
     */
    public function register() {
       /*  $weObj = $this->weObj;
        $oarray = $weObj->getCodeToken('Membership/register');
        $openid = $oarray['openid'];
        // echo $openid;die;
        $msg = I('msg', 0);
        $member = M('membership')->where(array('openid' => $openid))->find();
        if($member) {
            if(empty($member['headimgurl'])) {
                $userinfo = $weObj->getwechatinfo($openid);
                $data['nickname'] = $userinfo['nickname'];
                $data['sex'] = $userinfo['sex'];
                $data['province'] = $userinfo['province'];
                $data['city'] = $userinfo['city'];
                $data['country'] = $userinfo['country'];
                $data['headimgurl'] = $userinfo['headimgurl'];
                $data['privilege'] = $userinfo['privilege'];
                $data['unionid'] = $userinfo['unionid'];
                $data['subscribe'] = $userinfo['subscribe'];
                D('membership')->where(array('uid' => $member['uid']))->save($data);
            }
            if($member['status']) {
                $this->redirect('Membership/membercenter', array('uid' => $member['uid']));
            }
        } else {
            $userinfo = $weObj->getwechatinfo($openid);
            $data['openid'] = $openid;
            $data['nickname'] = $userinfo['nickname'];
            $data['sex'] = $userinfo['sex'];
            $data['province'] = $userinfo['province'];
            $data['city'] = $userinfo['city'];
            $data['country'] = $userinfo['country'];
            $data['headimgurl'] = $userinfo['headimgurl'];
            $data['privilege'] = $userinfo['privilege'];
            $data['unionid'] = $userinfo['unionid'];
            $data['subscribe'] = $userinfo['subscribe'];
           
            D('membership')->add($data);

        } */
        $this->getcity();
        $this->msg = I('msg',0);
        $this->display();
    }

    /**
     * 处理会员注册
     */
    public function dregister() {
        $id = I('uid');
        $data['name'] = I('name');
        $data['tel'] = I('tel');
        $data['member_id'] = randomkeys(6) . $id;
        $data['join_date'] = date('Y-m-d H:i:s');
      //  $change = I('change', 0);
     	$pwd = I('pwd');
        $pwdagain = I('pwdagain');
        if($pwd != $pwdagain){
        	$this->redirect('Membership/register',array('msg'=>'两次输入密码不同'));
        }
        $data['pwd'] = md5($pwd);
        if($uid){
        	$where = " uid='" . $id . "'";
        	D('Membership')->registerinfo($data, $where);
        }else{
        	$teldata = M('member')->where(array('tel'=>$data['tel']))->find();
        	if($teldata['uid']){
        		$this->redirect('Membership/register',array('msg'=>'手机号码已被注册过，请试试其他手机注册'));
        	}
        	/* echo "<pre>";
        	var_dump($data);die; */
        	M('Membership')->add($data);
        }
        $this->redirect('Membership/login', array('msg'=>'注册成功'));
      /*   if($change) {
            $this->redirect('Membership/index', array('uid' => $id,'msg'=>'修改成功'));
        } else {
            $this->redirect('Membership/login', array('msg'=>'注册成功'));
        } */

    }
    
    //绑定手机号
    public function clocktel(){
    	$uid = session('uid');;
    	$this->checkuid($uid,U('Membership/clocktel'));
    	$membership = M('membership')->where(array('uid'=>$uid))->field('tel')->find();
    	$this->oldtel = $membership['tel'];
    	if($_POST){
    		$tel = I('tel');
    		if($membership['tel']!=$tel){
    			$telhave = M('membership')->where(array('tel'=>$tel))->find();
    			if($telhave){
    				$msg = '该手机号码已经绑定过，请选择其他手机号码，或找回密码！';
    			}else{
    				$result = M('membership')->where(array('uid'=>$uid))->setField('tel', $tel);
    				if($result){
    					$msg = '绑定手机号码成功';
    					$this->oldtel = $tel;
    				}else{
    					$msg ='绑定手机号失败，请联系管理人员';
    				}
    			}
    		}
    		
    		
    	}    	
    	
    	$this->msg = $msg?$msg:0;
    	$this->back = U('Membership/index');
    	$this->display();
    }
    
    //忘记密码
    public function forgetpwd(){
    	if($_POST){
    		$tel = I('tel');
    		//$yanzheng = I('post.yanzheng');
    		//$yanzhengagain = I('post.yanzhengagain');
    		//if($yanzheng == $yanzhengagain){
    			$pwd = md5(I('post.pwd'));
    			//echo $pwd;die;
    			$result = M('membership')->where(array('tel'=>$tel))->setField('pwd', $pwd);
    			//echo $result;die;
    			if(!$result){
    				$this->redirect('Membership/login',array('msg'=>'修改密码成功！'));
    			}else{
    				$this->tel = $tel;
    				$this->msg = '修改密码失败，联系管理人员';
    				$this->display();
    			}
    		/* }else{
    			$this->msg = '验证码填写错误';
    			$this->tel = $tel;
    		} */
    	}else{
    		$this->msg = 0;
    		$this->display();
    	}
    }
    //注册登录验证
    public function rsendyz(){
    	//查看电话是否被注册过
    	$tel = I('tel');
    	$uid = M('membership')->where(array('tel'=>$tel))->field('uid')->find();
    	if($uid['uid']){
    		$data['msg']='电话号码已被注册过，请直接登录!';
    		$data['flag']=1;
    		$data['yanzhengma']='';
    	}else{
    		$yanzhengma = randyz(6);
    		$sendyz = 1;//调用发送接口返回数据
    		if($sendyz){
    			$data['msg']='验证码发送成功!';
    			$data['flag']=2;
    			$data['yanzhengma']=$yanzhengma;
    			//
    		}else{
    			$data['msg']='验证码发送失败，联系管理人员!';
    			$data['flag']=1;
    			$data['yanzhengma']=$yanzhengma;
    		}
    	}
    	
    	echo json_encode($data);
    }
    //找回密码向手机发起验证码
    public function sendyzm(){
    	$tel = I('tel');
    	$uid = session('uid');//针对于已登录用户
    	if(!$uid){//针对于未登录用户
    		$uid = M('membership')->where(array('tel'=>$tel))->field('uid')->find();
    	}
    	if(!$uid){
    		$data['msg']='电话号码错误!';
    		$data['flag']=1;
    		$data['yanzhengma']='';
    		//echo  json_encode($data);
    	}else{
    		$yanzhengma = randyz(6);
    		$sendyz = 1;//调用发送接口返回数据
    		if($sendyz){
    			$data['msg']='验证码发送成功!';
    			$data['flag']=2;
    			$data['yanzhengma']=$yanzhengma;
    			//
    		}else{
    			$data['msg']='验证码发送失败，联系管理人员!';
    			$data['flag']=1;
    			$data['yanzhengma']=$yanzhengma;
    		}
    	}
    	echo json_encode($data);
    	
    }
    
    //地址管理
    public function manageaddress(){
    	$uid = session('uid');
    	$this->checkuid($uid,U('Membership/manageaddress'));
    	
    	//var_dump($_POST);die;
    	if($_POST){
    		$address_id = I('post.address_id');
    		//设置默认收货地址
    		M('address')->where(array('uid'=>$uid))->setField('default_flag',0);
    		M('address')->where(array('address_id'=>$address_id))->setField('default_flag',1);
    		
    			
    	}
    	$address = M('address')->where(array('uid'=>$uid))->order('address_id desc')->select();//D('Address')->getAddress(array('uid'=>$uid));//
    	if(!$address){
    			//$back = U('Order/selectaddress',array('orderid'=>$orderid));
    			$this->redirect('Membership/address',array('back'=>'selectaddress','orderid'=>$orderid));
    	}
    			
    		//var_dump($address);die;
    	$this->address = $address;
    	$this->msg = 0;
    	$this->display();
    }
    
    //增加收货地址
    public function address(){
    	$uid = session('uid');
    	$this->checkuid($uid,U('Membership/address'));
    	$back = I('back');
    	$orderid = I('orderid');
    	if($_POST){
    		M('address')->where(array('uid'=>$uid,'default_flag'=>1))->setField('default_flag',0);
    		$data['uid'] = $uid;
    		$data['lastname']= I('lastname');
    		$data['phone'] = I('phone');
    		$data['address_2'] = I('address_2');
    		$prov_name = M('province')->where(array('code'=>I('provcode')))->field('name')->find();
    		$city_name = M('city')->where(array('code'=>I('citycode')))->field('name')->find();
    		$area_name = M('area')->where(array('code'=>I('area_id')))->field('name')->find();
    		$data['address_1'] =$prov_name['name'].$city_name['name'].$area_name['name'];
    		$data['provcode'] = I('provcode');
    		$data['citycode'] = I('citycode');
    		$data['area_id'] = I('area_id');
    		$data['add_date'] = date('Y-m-d H:i:s',time());
    		$data['default_flag'] = 1;
    		$result = M('address')->add($data);
    		if($back){
    			$this->redirect('Order/'.$back,array('orderid'=>$orderid));
    		}else{
    			$this->msg = '新增地址成功,请去我的地址中查看收货地址';
    			$this->display();
    		}
    	}else{
    		$this->member = M('membership')->where(array('uid'=>$uid))->field('name,tel,address')->find();
    		$this->msg = 0;
	    	$this->back = $back;
	    	$this->orderid = $orderid;
	    	$this->display();
    	}
    }
    
    //会员收藏
    public function mcollect(){
    	$uid = session('uid');
    	$this->checkuid($uid,U('Membership/mcollect'));
    	//echo $uid;die;
    	$order = 'co.collect_time desc';
    	$limit = '0,10';
    	$collectlist = D('Membership')->getCollect($uid,$order,$limit);
    	//var_dump($collectlist);die;
    	$this->collectlist = $collectlist;
    	$this->display();
    }
    
    //删除收藏
    public function delcollect(){
    	$uid = session('uid');
    	//$this->checkuid($uid);
    	$pid = I('pid');
    	/* if(!$pid){
    		$this->redirect('Membership/mcollect');
    	} */
    	$result = M('collect')->where(array('uid'=>$uid,'products_id'=>$pid))->delete();
    	if($result){
    		$data['flag']=1;
    		$data['msg'] ='删除收藏成功';
    	}else{
    		$data['flag']=0;
    		$data['msg'] = '删除收藏失败，请联系管理人员';
    	}
    	echo json_encode($data);
    }
    
    //会员提现管理
    public function deposit(){
    	$uid = session('uid');
    	$this->checkuid($uid,U('Membership/deposit'));
    	//echo $uid;die;
    	
    	if($_POST){//提交提现申请
    		$money = I('post.money');
    		$moneylogdetail = M('member_moneylog')->where(array('uid'=>$uid))->order('member_moneylog_id desc')->find();
    		//处理金钱交易
    		$active_money = $moneylogdetail['active_money']-$money;//计算现有可用金额
    		if($active_money<0){
    			$msg = '提取金额不能大于账户现有可用金额！';
    		}else{
    			//保存提现请求
    			$data1['member_bank_id'] = I('post.member_bank_id');
    			$data1['money'] = $money;
    			$data1['uid'] = $uid;
    			$data1['withdraw_date']=date('Y-m-d H:i:s', time());
    			$data1['flag'] = 0;
    			$withdrawid = M('member_withdraw')->add($data1);
    			if($withdrawid){
    				$data['uid'] = $uid;
    				$data['money_type'] = 4;
    				$data['affect_money'] = $money;
    				$data['active_money']=$active_money;
    				$data['account_money'] = $moneylogdetail['account_money'];
    				$data['freeze_money'] = $moneylogdetail['freeze_money']+$money;//计算冻结金额
    				$data['moneylog_affect_date']=date('Y-m-d H:i:s', time());
    				$data['u_ip']=getip();
    				$data['member_withdraw_id'] = $withdrawid;
    				$addmongylogid = M('member_moneylog')->add($data);
    				if($addmongylogid){
    					$msg = '提现申请成功';
    				}else{
    					M('member_withdraw')->where(array('member_withdraw_id'=>$withdrawid))->delete();
    					$msg = '提现申请失败，联系管理人员';
    				}
    				
    			}else{
    				M('member_withdraw')->where(array('member_withdraw_id'=>$withdrawid))->delete();
    				$msg = '提现申请失败，联系管理人员';
    			}
    			
    		}
    		
    	}
    	//$bank = M('member_banks')->where(array('uid'=>$uid))->order('member_bank_id desc')->find();
    	$moneylog = M('member_moneylog')->where(array('uid'=>$uid))->order('member_moneylog_id desc')->field('`active_money`+`freeze_money` as account,active_money,freeze_money')->find();
    	//echo M('member_moneylog')->getLastSql();die;
    	//var_dump($moneylog);die;
    	//$active_money = $moneylog['active_money']-$moneylog['freeze_money'];
    	/* if(!$bank['member_bank_id']){
    		$this->redirect('Membership/bindbank',array('back'=>'deposit'));
    	} */
    	//$totalw = D('MemberWithdraw')->getAllMoney($uid);提现总额
    	
    	//获取提现记录
    	$depositlist = D('MemberWithdraw')->getW($uid,'member_withdraw_id desc','0,8');//M('member_withdraw')->where(array('uid'=>$uid))->order('member_withdraw_id desc')->limit('0,3');//
    	//var_dump($depositlist);die;
    	//获取冻结记录
    	$fwhere['uid'] = $uid;
    	$fwhere['money_type'] = array('in','1,4');
    	$freeze = D('member_moneylog')->where($fwhere)->field('member_moneylog_id,affect_money,moneylog_affect_date,freeze_flag')->order('member_moneylog_id desc')->select();
    	//var_dump($freeze);die;
    	//获取金额变动记录
    	$allaccount = D('member_moneylog')->table('member_moneylog mm')->join('money_type mt ON mm.money_type=mt.money_type')->where(array('uid'=>$uid))->field('mm.affect_money,moneylog_affect_date,mt.name')->order('member_moneylog_id desc')->select();
    	//var_dump($allaccount);die;
    	
    	$member = M('membership')->where(array('uid'=>$uid))->field('name,headimgurl,headimg,member_id')->find();
    	//var_dump($depositlist);die;
    	//$this->$totalw =$totalw;
    	$this->depositlist = $depositlist?$depositlist:'';
    	$this->freeze = $freeze;
    	$this->allaccount = $allaccount;
    	$this->bank=$bank;
    	$this->moneylog =$moneylog ;
    	$this->member = $member;
    	$this->msg = $msg?$msg:0;
    	$this->display();
    }
    
    //会员绑定银行卡
    public function bindbank(){
    	$uid = session('uid');
    	$this->checkuid($uid,U('Membership/bindbank'));
    	if($_POST){
    		$data['bank_uname'] = I('post.bank_uname');
    		$data['bank_name'] = I('post.bank_name');
    		$data['bank_address'] = I('post.bank_address');
    		$data['bank_num'] = I('post.bank_num');
    		$data['uid'] = $uid;
    		$data['default_flag'] = 1;
    		$data['bank_add_time']= date('Y-m-d H:i:s',time());
    		$result = M('member_banks')->add($data);
    		if($result){
    			/* $back = I('post.back');
    			header($back); */
    			$this->redirect('Membership/deposit');
    		}else{
    			$msg = "绑定银行失败，请联系管理人员！";
    		}
    	}
    	$member = M('membership')->where(array('uid'=>$uid))->field('name,nickname')->find();

    	$this->back = U('Membership/index');
    	$this->msg = $msg?$msg:0;
    	$this->member = $member;
    	$this->display();
    }
    
    //会员订单管理
    public function ordermanage(){
    	$uid = session('uid');
    	$this->checkuid($uid,U('Membership/ordermanage'));
    	$order_status_id = I('ostatusid',0);
    	$bsflag = I('bsflag','1');//查看买入还是卖出商品
    	if($bsflag){
    		if($bsflag==1){
    			$where['uid']=$uid;
    		}else{
    			$where['publish_uid'] = $uid;
    		}
    	}else{
    		//获取所有订单
    		$map['publish_uid'] = $uid;
    		$map['uid']  = $uid;
    		$map['_logic'] = 'or';
    		$where['_complex'] = $map;
    	}
    	//var_dump($where);die;
    	
    	if($order_status_id){
    		if($order_status_id<3){
    			$where['order_status_id']=array('lt',3);
    		} else if($order_status_id ==3){
    			$where['order_status_id'] = array('not in',' 1,4,5,6,7,8,9,10,11,12');
    		}
    		else if($order_status_id ==5 && $bsflag==2){
    			$where['order_status_id'] = array('in','5,6');
    		}
    		else{
    			
    			$where['order_status_id']=$order_status_id;
    		}
    	}
    	//var_dump($where);die;
    	//$where['o.order_status_id']=$order_status_id;
    	$order = 'order_id desc';
    	$field = 'products_id,products_name,products_type,order_id,order_type,order_date_added,shipping_lastname,tel,uid,publish_uid,order_status_id, os_name,delivery_num,delivery_company';
    	$orderList = D('Order')->getMemberOrder($where,$order,$field);
    	/*   echo "<pre>";
    	var_dump($orderList);die;   */
    	$express = M('express')->where(array('express_status'=>1))->field('express_name')->select();
    	//var_dump($express);die;
    	$this->express = $express;
    	$this->bsflag=$bsflag;
    	$this->orderList = $orderList;
    	$this->ostatusid = $order_status_id;
    	$this->uid =$uid;
    	$this->msg = I('msg',0);
    	$this->display();
    }
	
    //会员浏览记录查看
    public function history(){
    	$uid = session('uid');
    	$this->checkuid($uid,U('Membership/history'));
    	$order = 'co.browsing_time desc';
    	$limit = '0,10';
    	$collectlist = D('Membership')->getBrowsing($uid,$order,$limit);
    	//var_dump($collectlist);die;
    	$this->collectlist = $collectlist;
    	$this->display();
    }
    
    //会员留言信箱
    public function leaveword(){
    	$uid = session('uid');
    	$this->checkuid($uid,U('Membership/leaveword'));
    	//echo $uid;die;
    	$map['l.uid'] = $uid;
    	$map['l.to_uid']  = $uid;
    	$map['_logic'] = 'or';
    	$where['_complex'] = $map;
    	$where['l.reply_leaveword_id']=0;
    	$wordlist = D('Leaveword')->getLeaveById($where);
    	//var_dump($wordlist);die; 
    	//$mname = M('membership')->where(array('uid'=>$uid))->field('name')->find();
    	
    	//$this->mname = $mname['name'];
    	$this->uid = $uid;
    	$this->wordlist = $wordlist;
    	$this->display();
    }
    
    //留言信箱详情及回复
    public function leavewordDetail(){
    	$uid = session('uid');
    	$leaveword_id = I('leavewordId','');
    	$this->checkuid($uid,U('Membership/leaveword',array('leavewordId'=>$leaveword_id)));
    	$leaveword_id = I('leavewordId','');
    	if(!$leaveword_id){
    		$this->redirect('Membership/leaveword');
    	}
    	if($_POST){
    		$leaveword = M('leaveword')->where(array('leaveword_id'=>$leaveword_id))->field('uid,to_uid,products_id')->find();
    		if($uid==$leaveword['uid']){
    			$to_uid = $leaveword['to_uid'];
    			$data['leaveword_type'] = 0;
    		}else{
    			$to_uid = $leaveword['uid'];
    			$data['leaveword_type'] = 1;
    		}
    		//var_dump($leaveword);
    		$comment = I('post.comment');
    		//$data['leaveword_type']='1';
    		$data['uid'] = $uid;
    		$data['to_uid'] = $to_uid;
    		$data['products_id'] = $leaveword['products_id'];
    		$data['comment'] = $comment;
    		$data['leaveword_date'] = date('Y-m-d H:i:s',time());
    		$data['reply_leaveword_id'] = $leaveword_id;
    		//var_dump($data);die;
    		$result = M('leaveword')->add($data);
    	}
    	$map['leaveword_id'] = $leaveword_id;
    	$map['reply_leaveword_id']  = $leaveword_id;
    	$map['_logic'] = 'or';
    	$where['_complex'] = $map;
    		
    	$talleach = D('Leaveword')->getAllLeave($where);
    	//获取参与人员姓名
    	$mname = M('membership')->where(array('uid'=>$uid))->field('name')->find();
    	//var_dump($talleach);    	
    	if($talleach[0]['uid']==$uid){
    		$buid = $talleach[0]['to_uid'];    		
    	}else{
    		$buid = $talleach[0]['uid'];    		
    	}
    	$bname = M('membership')->where(array('uid'=>$buid))->field('name')->find();
    	//echo $uid."  ".$buid.$bname['name'];die;
    	$this->talleach = $talleach;
    	$this->bname = $bname['name'];
    	$this->mname=$mname['name'];
    	$this->leavewordid = $leaveword_id;
    	$this->uid = $uid;
    	$this->display();
    	
    }
    
    //获取意见反馈记录
    public function report(){
    	$uid = session('uid');
    	$this->checkuid($uid,U('Membership/report'));
    	//echo $uid;die;
    	if(IS_POST){
    		$data['uid'] = $uid;
    		$data['comment'] = I('post.comment');
    		$data['report_date'] = date('Y-m-d H:i:s', time());
    		$data['report_type'] = 1;
    		$result = M('report')->add($data);
    		if(!$result){
    			$msg = '回复意见失败！';
    		}
    	}
    	//获取自己投诉的内容
    	$map['uid'] = $uid;
    	$map['to_uid']  = $uid;
    	$map['_logic'] = 'or';
    	$where['_complex'] = $map;
    	$where['reply_report_id']=0;
    	$wordlist = D('Report')->getReportById($where,$uid);
    	//var_dump($wordlist);die;
    	
    	//获取非自己投诉，系统留言
    	foreach($wordlist as $key=>$val){
    		$myreport[]=$val['report_id'];
    	}
    	//var_dump($myreport);die;
    	$where1['to_uid'] = $uid;
    	$where1['reply_report_id']=array('not in',$myreport);
    	$Systemlist = D('Report')->getReportById($where1,$uid,1);
    	//die;
    	if($wordlist&&!$Systemlist){
    		$allword=$wordlist;
    	}elseif($Systemlist&&!$wordlist){
    		$allword=$Systemlist;
    	}else{
    		$allword = array_merge($wordlist,$Systemlist);
    		//var_dump($allword);die;
    		foreach($allword as $key=>$val){
    			$num1[$key] = $val['report_id'];
    		}
    		//var_dump($num1);
    		array_multisort($num1,SORT_DESC,$allword);
    	}
    	//var_dump($Systemlist);die;
    	
    //	var_dump($allword);die;
    	//$mname = M('membership')->where(array('uid'=>$uid))->field('name')->find();
    	 
    	//$this->mname = $mname['name'];
    	$this->msg =$msg?$msg:0;
    	$this->allword = $allword;
    	//$this->Systemlist = $Systemlist;
    	$this->display();
    }
    //获取意见反馈详情
    public function reportDetail(){
    	$uid = session('uid');
    	$reportId = I('reportId');
    	$this->checkuid($uid,U('Membership/report',array('reportId'=>$reportId)));
    	//$reportId = I('reportId');
    	if(IS_POST){
    		$data['uid'] = $uid;
    		$data['comment'] = I('post.comment');
    		$data['report_date'] = date('Y-m-d H:i:s', time());
    		$data['reply_report_id'] = $reportId;
    		$result = M('report')->add($data);
    		if(!$result){
    			$msg = '回复意见失败！';
    		}
    	}
    	//获取自己投诉的内容
    	$map['uid'] = $uid;
    	$map['to_uid']  = $uid;
    	$map['_logic'] = 'or';
    	$where['_complex'] = $map;
    	$map1['reply_report_id'] = $reportId;
    	$map1['report_id'] = $reportId;
    	$map1['_logic'] = 'or';
    	$where['_string']='report_id='.$reportId." or reply_report_id=".$reportId;
    	//var_dump($where);die;
    	$detail = D('Report')->getAllReport($where);
    	//var_dump($detail);die;
    	$this->detail = $detail;
    	$this->reportId = $reportId;
    	$this->uid = $uid;
    	$this->msg = $msg?$msg:0;
    	$this->display();
    	
    }
   
}